


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > BoardFactory</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.board</a>
</div>

<h1>Coverage Summary for Class: BoardFactory (nl.tudelft.jpacman.board)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">BoardFactory</td>
<td class="coverageStat">
  <span class="percent">
    20%
  </span>
  <span class="absValue">
    (1/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    5.3%
  </span>
  <span class="absValue">
    (1/19)
  </span>
</td>
</tr>
  <tr>
    <td class="name">BoardFactory$Ground</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$122921973</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$122921973$auxiliary$3T311QSE</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$122921973$auxiliary$8CXO6IiD</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$122921973$auxiliary$M6vbPoh9</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$122921973$auxiliary$NAKSqdpH</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$122921973$auxiliary$pWuzsflH</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$Wall</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    9.1%
  </span>
  <span class="absValue">
    (1/11)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    3.4%
  </span>
  <span class="absValue">
    (1/29)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package nl.tudelft.jpacman.board;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import nl.tudelft.jpacman.npc.Ghost;
<i class="no-highlight">4</i>&nbsp;import nl.tudelft.jpacman.sprite.PacManSprites;
<i class="no-highlight">5</i>&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
<i class="no-highlight">6</i>&nbsp;
<i class="no-highlight">7</i>&nbsp;/**
<i class="no-highlight">8</i>&nbsp; * A factory that creates {@link Board} objects from 2-dimensional arrays of
<i class="no-highlight">9</i>&nbsp; * {@link Square}s.
<i class="no-highlight">10</i>&nbsp; *
<i class="no-highlight">11</i>&nbsp; * @author Jeroen Roosen 
<i class="no-highlight">12</i>&nbsp; */
<b class="fc"><i class="no-highlight">13</i>&nbsp;public class BoardFactory {</b>
<i class="no-highlight">14</i>&nbsp;
<i class="no-highlight">15</i>&nbsp;    /**
<i class="no-highlight">16</i>&nbsp;     * The sprite store providing the sprites for the background.
<i class="no-highlight">17</i>&nbsp;     */
<i class="no-highlight">18</i>&nbsp;    private final PacManSprites sprites;
<i class="no-highlight">19</i>&nbsp;
<i class="no-highlight">20</i>&nbsp;    /**
<i class="no-highlight">21</i>&nbsp;     * Creates a new BoardFactory that will create a board with the provided
<i class="no-highlight">22</i>&nbsp;     * background sprites.
<i class="no-highlight">23</i>&nbsp;     *
<i class="no-highlight">24</i>&nbsp;     * @param spriteStore
<i class="no-highlight">25</i>&nbsp;     *            The sprite store providing the sprites for the background.
<i class="no-highlight">26</i>&nbsp;     */
<b class="nc"><i class="no-highlight">27</i>&nbsp;    public BoardFactory(PacManSprites spriteStore) {</b>
<b class="nc"><i class="no-highlight">28</i>&nbsp;        this.sprites = spriteStore;</b>
<b class="nc"><i class="no-highlight">29</i>&nbsp;    }</b>
<i class="no-highlight">30</i>&nbsp;
<i class="no-highlight">31</i>&nbsp;    /**
<i class="no-highlight">32</i>&nbsp;     * Creates a new board from a grid of cells and connects it.
<i class="no-highlight">33</i>&nbsp;     *
<i class="no-highlight">34</i>&nbsp;     * @param grid
<i class="no-highlight">35</i>&nbsp;     *            The square grid of cells, in which grid[x][y] corresponds to
<i class="no-highlight">36</i>&nbsp;     *            the square at position x,y.
<i class="no-highlight">37</i>&nbsp;     * @return A new board, wrapping a grid of connected cells.
<i class="no-highlight">38</i>&nbsp;     */
<i class="no-highlight">39</i>&nbsp;    public Board createBoard(Square[][] grid) {
<b class="nc"><i class="no-highlight">40</i>&nbsp;        assert grid != null;</b>
<i class="no-highlight">41</i>&nbsp;
<b class="nc"><i class="no-highlight">42</i>&nbsp;        Board board = new Board(grid);</b>
<i class="no-highlight">43</i>&nbsp;
<b class="nc"><i class="no-highlight">44</i>&nbsp;        int width = board.getWidth();</b>
<b class="nc"><i class="no-highlight">45</i>&nbsp;        int height = board.getHeight();</b>
<b class="nc"><i class="no-highlight">46</i>&nbsp;        for (int x = 0; x &lt; width; x++) {</b>
<b class="nc"><i class="no-highlight">47</i>&nbsp;            for (int y = 0; y &lt; height; y++) {</b>
<b class="nc"><i class="no-highlight">48</i>&nbsp;                Square square = grid[x][y];</b>
<b class="nc"><i class="no-highlight">49</i>&nbsp;                for (Direction dir : Direction.values()) {</b>
<b class="nc"><i class="no-highlight">50</i>&nbsp;                    int dirX = (width + x + dir.getDeltaX()) % width;</b>
<b class="nc"><i class="no-highlight">51</i>&nbsp;                    int dirY = (height + y + dir.getDeltaY()) % height;</b>
<b class="nc"><i class="no-highlight">52</i>&nbsp;                    Square neighbour = grid[dirX][dirY];</b>
<b class="nc"><i class="no-highlight">53</i>&nbsp;                    square.link(neighbour, dir);</b>
<i class="no-highlight">54</i>&nbsp;                }
<i class="no-highlight">55</i>&nbsp;            }
<i class="no-highlight">56</i>&nbsp;        }
<i class="no-highlight">57</i>&nbsp;
<b class="nc"><i class="no-highlight">58</i>&nbsp;        return board;</b>
<i class="no-highlight">59</i>&nbsp;    }
<i class="no-highlight">60</i>&nbsp;
<i class="no-highlight">61</i>&nbsp;    /**
<i class="no-highlight">62</i>&nbsp;     * Creates a new square that can be occupied by any unit.
<i class="no-highlight">63</i>&nbsp;     *
<i class="no-highlight">64</i>&nbsp;     * @return A new square that can be occupied by any unit.
<i class="no-highlight">65</i>&nbsp;     */
<i class="no-highlight">66</i>&nbsp;    public Square createGround() {
<b class="nc"><i class="no-highlight">67</i>&nbsp;        return new Ground(sprites.getGroundSprite());</b>
<i class="no-highlight">68</i>&nbsp;    }
<i class="no-highlight">69</i>&nbsp;
<i class="no-highlight">70</i>&nbsp;    /**
<i class="no-highlight">71</i>&nbsp;     * Creates a new square that cannot be occupied by any unit.
<i class="no-highlight">72</i>&nbsp;     *
<i class="no-highlight">73</i>&nbsp;     * @return A new square that cannot be occupied by any unit.
<i class="no-highlight">74</i>&nbsp;     */
<i class="no-highlight">75</i>&nbsp;    public Square createWall() {
<b class="nc"><i class="no-highlight">76</i>&nbsp;        return new Wall(sprites.getWallSprite());</b>
<i class="no-highlight">77</i>&nbsp;    }
<i class="no-highlight">78</i>&nbsp;
<i class="no-highlight">79</i>&nbsp;    /**
<i class="no-highlight">80</i>&nbsp;     * A wall is a square that is inaccessible to anyone.
<i class="no-highlight">81</i>&nbsp;     *
<i class="no-highlight">82</i>&nbsp;     * @author Jeroen Roosen
<i class="no-highlight">83</i>&nbsp;     */
<i class="no-highlight">84</i>&nbsp;    private static final class Wall extends Square {
<i class="no-highlight">85</i>&nbsp;
<i class="no-highlight">86</i>&nbsp;        /**
<i class="no-highlight">87</i>&nbsp;         * The background for this square.
<i class="no-highlight">88</i>&nbsp;         */
<i class="no-highlight">89</i>&nbsp;        private final Sprite background;
<i class="no-highlight">90</i>&nbsp;
<i class="no-highlight">91</i>&nbsp;        /**
<i class="no-highlight">92</i>&nbsp;         * Creates a new wall square.
<i class="no-highlight">93</i>&nbsp;         *
<i class="no-highlight">94</i>&nbsp;         * @param sprite
<i class="no-highlight">95</i>&nbsp;         *            The background for the square.
<i class="no-highlight">96</i>&nbsp;         */
<b class="nc"><i class="no-highlight">97</i>&nbsp;        Wall(Sprite sprite) {</b>
<b class="nc"><i class="no-highlight">98</i>&nbsp;            this.background = sprite;</b>
<b class="nc"><i class="no-highlight">99</i>&nbsp;        }</b>
<i class="no-highlight">100</i>&nbsp;
<i class="no-highlight">101</i>&nbsp;        @Override
<i class="no-highlight">102</i>&nbsp;        public boolean isAccessibleTo(Unit unit) {
<b class="nc"><i class="no-highlight">103</i>&nbsp;            return false;</b>
<i class="no-highlight">104</i>&nbsp;        }
<i class="no-highlight">105</i>&nbsp;
<i class="no-highlight">106</i>&nbsp;        @Override
<i class="no-highlight">107</i>&nbsp;        public Sprite getSprite() {
<b class="nc"><i class="no-highlight">108</i>&nbsp;            return background;</b>
<i class="no-highlight">109</i>&nbsp;        }
<i class="no-highlight">110</i>&nbsp;    }
<i class="no-highlight">111</i>&nbsp;
<i class="no-highlight">112</i>&nbsp;    /**
<i class="no-highlight">113</i>&nbsp;     * A ground square is a square that is accessible to anyone.
<i class="no-highlight">114</i>&nbsp;     *
<i class="no-highlight">115</i>&nbsp;     * @author Jeroen Roosen
<i class="no-highlight">116</i>&nbsp;     */
<i class="no-highlight">117</i>&nbsp;    private static final class Ground extends Square {
<i class="no-highlight">118</i>&nbsp;
<i class="no-highlight">119</i>&nbsp;        /**
<i class="no-highlight">120</i>&nbsp;         * The background for this square.
<i class="no-highlight">121</i>&nbsp;         */
<i class="no-highlight">122</i>&nbsp;        private final Sprite background;
<i class="no-highlight">123</i>&nbsp;
<i class="no-highlight">124</i>&nbsp;        /**
<i class="no-highlight">125</i>&nbsp;         * Creates a new ground square.
<i class="no-highlight">126</i>&nbsp;         *
<i class="no-highlight">127</i>&nbsp;         * @param sprite
<i class="no-highlight">128</i>&nbsp;         *            The background for the square.
<i class="no-highlight">129</i>&nbsp;         */
<b class="nc"><i class="no-highlight">130</i>&nbsp;        Ground(Sprite sprite) {</b>
<b class="nc"><i class="no-highlight">131</i>&nbsp;            this.background = sprite;</b>
<b class="nc"><i class="no-highlight">132</i>&nbsp;        }</b>
<i class="no-highlight">133</i>&nbsp;
<i class="no-highlight">134</i>&nbsp;        @Override
<i class="no-highlight">135</i>&nbsp;        public boolean isAccessibleTo(Unit unit) {
<b class="nc"><i class="no-highlight">136</i>&nbsp;            return true;</b>
<i class="no-highlight">137</i>&nbsp;        }
<i class="no-highlight">138</i>&nbsp;
<i class="no-highlight">139</i>&nbsp;        @Override
<i class="no-highlight">140</i>&nbsp;        public Sprite getSprite() {
<b class="nc"><i class="no-highlight">141</i>&nbsp;            return background;</b>
<i class="no-highlight">142</i>&nbsp;        }
<i class="no-highlight">143</i>&nbsp;    }
<i class="no-highlight">144</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-05-22 18:55</div>
</div>
</body>
</html>
